// 传入金额数字，返回格式化后的金额格式
export function moneyFormat(num) {
  num = num.toString();
  num = num.replace(/[^\d.]/g, ''); //清除“数字”和“.”以外的字符
  num = num.replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3'); //只能输入两个小数
  if (num.includes('..')) {
    num = num.substring(0, num.length - 1);
  }
  if (num.indexOf('.') == 0) {
    num = '0.';
  }
  if (num.indexOf('.') < 0 && num != '') {
    num = parseFloat(num);
  }
  return num;
}
